<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ProcessesArchive;
use App\Models\StandardProcess;
use App\Models\Workshop;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ProcessesArchiveController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(ProcessesArchive::with('workshop'), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('workshop.title', admin_trans('processes-archive.fields.workshop_title'));
            $grid->column('title');
            $grid->column('type')->using(admin_trans('processes-archive.options.type'));
            $grid->column('sort');
            $grid->column('status')->using(admin_trans('processes-archive.options.status'));
            $grid->column('is_wait')->using(admin_trans('processes-archive.options.is_wait'));
            $grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('workshop_id', admin_trans('processes-archive.fields.workshop_title'))->select(Workshop::where('status', DEFAULT_STATUS_SUCCESS)
                    ->pluck('title', 'id'));
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ProcessesArchive(), function (Show $show) {
            $show->field('id');
            $show->field('workshop_id');
            $show->field('title');
            $show->field('type')->using(admin_trans('processes-archive.options.type'));
            $show->field('sort');
            $show->field('status')->using(admin_trans('processes-archive.options.status'));
            $show->field('is_wait')->using(admin_trans('processes-archive.options.is_wait'));
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ProcessesArchive(), function (Form $form) {
            $form->display('id');
            $form->select('workshop_id')->options(Workshop::where('status', DEFAULT_STATUS_SUCCESS)
                ->pluck('title', 'id'))
                ->required();
            $form->text('title');
            $form->radio('type')->options(admin_trans('processes-archive.options.type'))->default('1');
            $form->text('sort');
            $form->radio('status')->options(admin_trans('processes-archive.options.status'))->default('1');
            $form->radio('is_wait')->options(admin_trans('processes-archive.options.is_wait'))->default('1');
            $form->radio('processes_type')->options(admin_trans('processes-archive.options.processes_type'));
            $form->select('standard_process_id')->options(StandardProcess::where('status', DEFAULT_STATUS_SUCCESS)
                ->pluck('title', 'id'));
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
